<template>
  <el-dialog title="新增流程分类" :visible.sync="dialogVisible" width="30%" :append-to-body="true">
    <el-form ref="addForm" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="编号" prop="code" label-width="100px">
        <el-input v-model="form.code"></el-input>
       </el-form-item>
      <el-form-item label="分类名称" prop="type" label-width="100px">
        <el-input v-model="form.type"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('addForm')">保存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import TreeSelect from "@/components/basic-treeselect/treeselect";
import { activeUrl } from "@/config/env";
const urls = {
  save: activeUrl + "/category/category/add",
  list: activeUrl + "/category/category/list"
};
export default {
  data() {
    return {
      dialogVisible: false,
      data: [],
      defaultCheckedKeys: [],
      form: {
        type: null,
        code : null
      },
      rules: {
        type: [{ required: true, message: "请输入分类名称", trigger: "blur" }]
      }
    };
  },
  components: {
    TreeSelect
  },
  methods: {
    popoverHide(checkedIds, checkedData) {
      this.form.menus = checkedIds.toString();
    },
    show() {
      this.dialogVisible = true;
      if (this.$refs["addForm"]) {
        this.$refs["addForm"].resetFields();
      }
      this.fetch();
    },
    onSubmit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          axios.post(urls.save, this.form).then(res => {
            this.$message(res.data.result);
            this.dialogVisible = false;
            this.$emit("refresh");
          });
        }
        return false;
      });
    },
    fetch() {
      axios.get(urls.list).then(res => {
        this.data = res.data.result; 
      });
    }
  }
};
</script>